using System;
using FireStarterModeller.BO;

namespace FireStarterModeller.Test.BO
{
    public class TestUtilsDMObjectIdentity
    {
        /// <summary>
        /// Creates a new saved DMObjectIdentity with a random value assigned to every property
        /// </summary>
        public static DMObjectIdentity CreateSavedDMObjectIdentity()
        {
            DMObjectIdentity dMObjectIdentity = CreateUnsavedValidDMObjectIdentity();
            dMObjectIdentity.Save();
            return dMObjectIdentity;
        }

        /// <summary>
        /// Creates a new unsaved DMObjectIdentity with a random value assigned to every property
        /// </summary>
        public static DMObjectIdentity CreateUnsavedValidDMObjectIdentity()
        {
            DMObjectIdentity dMObjectIdentity = CreateUnsavedValidDMObjectIdentity_NoDMClass();
            DMClass dmClass = TestUtilsShared.CreateUnsavedValidDMClass();
            var dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty(dmClass);
            dMObjectIdentity.ClassID = dmClass.ClassID;
            dMObjectIdentity.Properties.Add(dmProperty);
            return dMObjectIdentity;
        } 
        /// <summary>
        /// Creates a new unsaved DMObjectIdentity with a random value assigned to every property
        /// </summary>
        public static DMObjectIdentity CreateUnsavedValidCompositeDMObjectIdentity()
        {
            DMObjectIdentity dMObjectIdentity = CreateUnsavedValidDMObjectIdentity_NoDMClass();
            DMClass dmClass = TestUtilsShared.CreateUnsavedValidDMClass();
            TestUtilsShared.CreateUnsavedValidDMProperty(dmClass);
            TestUtilsShared.CreateUnsavedValidDMProperty(dmClass);
            dMObjectIdentity.ClassID = dmClass.ClassID;
            dMObjectIdentity.Properties.Add(dmClass.Properties[0]);
            dMObjectIdentity.Properties.Add(dmClass.Properties[1]);
            return dMObjectIdentity;
        } 
        /// <summary>
        /// Creates a new unsaved DMObjectIdentity with a random value assigned to every property
        /// </summary>
        public static DMObjectIdentity CreateUnsavedValidDMObjectIdentity_NoDMClass()
        {
            DMObjectIdentity dMObjectIdentity = new DMObjectIdentity
                                                    {
                                                        IsObjectID = TestUtilsShared.GetRandomBoolean(),
                                                        Generated = TestUtilsShared.GetRandomBoolean(),
                                                        MappedPrimaryKeyID = Guid.NewGuid()
                                                    };
            return dMObjectIdentity;
        }
	    
        /// <summary>
        /// Creates a new unsaved DMObjectIdentity where all properties are null, except ID properties
        /// and those with default values.  If there are compulsory properties without
        /// defaults, saving the object will throw an exception.
        /// </summary>
        public static DMObjectIdentity CreateUnsavedDefaultDMObjectIdentity()
        {
            DMObjectIdentity dMObjectIdentity = new DMObjectIdentity();
            return dMObjectIdentity;
        }

        public static DMObjectIdentity CreateSavedDMObjectIdentity(DMClass dmClass)
        {
            DMObjectIdentity dMObjectIdentity = CreateUnsavedValidDMObjectIdentity_NoDMClass();
            dMObjectIdentity.Class = dmClass;
            DMProperty dmProp = TestUtilsDMProperty.CreateUnsavedValidDMProperty(dmClass, false);
            dMObjectIdentity.Properties.Add(dmProp);
            dmClass.Save();
            return dMObjectIdentity;
        }

    }
}